package minFlips;

public class Solution {

    public int minFlips(int[][] grid) {
        //分别按行和列反转

        int c_r = 0;
        //按行
        for(int i =0; i < grid.length; i+=1){
            int left=0, right = grid[i].length-1;
            while(left < right){
                if(grid[i][left] != grid[i][right]){
                    c_r +=1;
                }
                left +=1;
                right -=1;
            }
        }
        int c_c = 0;
        //按列
        for(int j =0; j <grid[0].length; j+=1){
            int left =0,right = grid.length -1;
            while(left < right){
                if(grid[left][j] != grid[right][j]){
                    c_c +=1;
                }
                left +=1;
                right -=1;
            }
        }

        return Math.min(c_r, c_c);

    }

}
